<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>交换li元素位置</title>
    <style>

    </style>
</head>
<body>
   <h1></h1>
    <button disabled>
        点击抢购
    </button>
    <script>
        function doClick(){
            alert("抢购成功！")
        }
        let h1 = document.querySelector('h1')
        let btn = document.querySelector('button')
        btn.disabled = true;
        function doTime(date){
            let now = new Date()
            let end = new Date(date)
            let leftTime = (end - now) / 1000 //相差的秒数
            let day,hour,minute,second
            if(leftTime > 0){
                day = Math.floor(leftTime / 60 / 60 /24)
                hour = Math.floor(leftTime / 60/60%24)
                minute = Math.floor(leftTime /60%60)
                second = Math.floor(leftTime%60)
                h1.innerHTML = `${day}天 
                ${hour} 时
                ${minute} 分
                ${second} 秒`
            }else{
                clearInterval(time)
                btn.disabled = false
                btn.setAttribute('onclick','doClick()')
            }
        }
        let time = setInterval(() => {
            doTime("2021-09-16T22:49:00")
        },0)
    </script>
</body>
</html>